package com.zcg.blogger.util;

import java.util.Random;

public class RandomUtil {
	
	private static Random random = new Random();
	
	/**
	 * 随机生成4位验证码
	 * @return
	 */
	public static String checkCode(){
		StringBuffer checkCode = new StringBuffer();
		for(int i = 0;i<4;i++){
			checkCode.append(randomChar());
		}
		return checkCode.toString();
	}
	
	/**
	 * 随机生成一个字符
	 * @return
	 */
	public static char randomChar(){
		switch (random.nextInt(3)) {
		case 0:
			return (char) (random.nextInt(10)+48);
		case 1:
			return (char) (random.nextInt(26)+97);
		case 2:
			return (char) (random.nextInt(26)+65);
		default:
			break;
		}
		return 'g';
	}
}
